<?php
     include_once('../../src/classes/class.mssql.php');  
     $db = new MSSQL();
     $comtec_id_mainteiner = $_GET['id'];
?>    
<fieldset class="curved">
	  <legend>Ingresar</legend>
			<table style="margin: 10px auto; border-spacing: 10px;">
			    <tr>
				<td width="200">Tag Id.</td>
				<td><input type="text" size="40" maxlength="10" id="tag_id_machine" /></td>
				<td width="200">Marca</td>
				<td><input type="text" size="40" maxlength="20" id="brand" /></td>
			    </tr>
			    <tr>
				<td width="200">Cod. mantenedor</td>
				<td><input type="text" size="40" maxlength="10" id="cod_mainteiner" /></td>
				<td width="200">Modelo</td>
				<td><input type="text" size="40" maxlength="20" id="model" /></td>
			    </tr>
			    <tr>
				<td width="200">A&ntilde;o</td>
				<td><input type="text" maxlength="5" id="year" size="40" /></td>
                                <td width="200">Encargado</td>
                                <td width="200">
                                 <select id="comtec_id_responsible" style="width:257px;">
                                  <option value="0" selected>Selecci&oacute;n...</option>
                                  <?
                                    $responsible = $db->query("SELECT comtec_id_responsible, name, lastname1, lastname2, status_reg FROM responsible WHERE comtec_id_mainteiner = $comtec_id_mainteiner ");
                                    while ($r = sqlsrv_fetch_array($responsible,SQLSRV_FETCH_ASSOC))
                                    {
                                     if ($r['status_reg'] == 1)
                                     {
                                      echo "<option value=".$r['comtec_id_responsible'].">".$r['name']." ".$r['lastname1']." ".$r['lastname2']."</option>";
                                     }
                                    }
                                  ?>
                                 </select>
                              </td>
			    </tr>
			    <tr>
				<td width="200">Propietario</td>
				<td>
				    <select id="comtec_id_owner" style="width:257px;">
					<option value="0" selected>Selecci&oacute;n...</option>
					<?
					$owners = $db->query("SELECT comtec_id_owner, company_name FROM owner WHERE comtec_id_mainteiner=$comtec_id_mainteiner AND status_reg=1 ORDER BY company_name ASC");					
					while ($r = sqlsrv_fetch_array($owners,SQLSRV_FETCH_ASSOC))
					{
					 echo "<option value=".$r['comtec_id_owner'].">".$r['company_name']."</option>";
					}
					?>
				    </select>
				</td>

				<td width="200">Configuraci&oacute;n de Mantenci&oacute;n</td>
				<td>
				    <select id="comtec_id_configman" style="width:257px;" >
					<option value="0" selected>Selecci&oacute;n...</option>
					<?
					    $config = $db->query("SELECT comtec_id_configman, configman_name FROM configman WHERE comtec_id_mainteiner=$comtec_id_mainteiner AND status_reg=1 ");					    
					    while ($r = sqlsrv_fetch_array($config,SQLSRV_FETCH_ASSOC))
					    {
						echo "<option value=".$r['comtec_id_configman'].">".$r['configman_name']."</option>";
					    }
					?>
				    </select>
				</td>
				<td>
                                    <!--TODO agregar la description confman-->
				    <div id="descriptionConfman"></div>
				</td>
			    </tr>
			    <tr>
				<td width="200">C&oacute;d. propietario</td>
				<td><input type="text" size="40" maxlength="10" id="cod_owner" /></td>
                                <td width="200">Fecha de instalaci&oacute;n</td>                                
                                <td width="200">
                                 <?
                                   $optionsXML = simplexml_load_file("../../xml/days.xml"); 
                                   $options =  $optionsXML->xpath("//day/text()");
                                   echo '<select id="install_day" style="width:65px;">';
                                   while(list( $key , $value) = each($options)) {
                                    if ($key>9){
                                     echo '<option value='.$key.'>' . $value . '</option>';
                                    }else{
                                          echo '<option value=0'.$key.'>' . $value . '</option>';
                                         }
                                   }
                                   echo '</select>';
                                 ?>
                                  <?
                                    $optionsXML = simplexml_load_file("../../xml/months.xml"); 
                                    $options =  $optionsXML->xpath("//month/text()");
                                    echo '<select id="install_month" style="width:105px;">';
                                    while(list( $key , $value) = each($options)) {  
                                     if ($key>9){   
                                      echo '<option value='.$key.'>' . $value . '</option>';
                                     }else{
                                       echo '<option value=0'.$key.'>' . $value . '</option>';
                                      }
                                    }
                                    echo '</select>';
                                   ?>                    
                                   <?
                                     $optionsXML = simplexml_load_file("../../xml/years.xml"); 
                                     $options =  $optionsXML->xpath("//year/text()");
                                     echo '<select id="install_year" style="width:78px;">';
                                     while(list($key,$value) = each($options)) {   
                                      echo '<option value='.$value.'>' . $value . '</option>';
                                     }
                                     echo '</select>';
                                   ?>
                                </td>
			    </tr>
			    <tr>
				<td width="200">Notas</td>
			    </tr>
			    <tr>
				<td colspan="4"><textarea id="notes" rows="3" cols="120" style="resize:none"></textarea></td>
			    </tr>
                            <tr>
                                <td>
                                    <input type="button" name="addMachine" value="Guardar" onclick="javascript:saveMachine()" />
                                    <input type="button" value="Cancelar" onclick="javascript:loadMachines();" />
                                </td>
                            </tr>
			</table>
<div id="result"></div> 
</fieldset>